package com.imooc.security.demo.web;

import com.imooc.security.demo.object.UserQueryCondition;
import com.imooc.security.demo.object.UserVo;
import com.imooc.security.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @Author sherry
 * @Description
 * @Date Create in 2019-03-13
 * @Modified By:
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping
    public ResponseEntity getUserList(UserQueryCondition userQueryCondition,@PageableDefault(page = 0,size = 15,sort = {"name"}) Pageable pageable) {

        log.info("请求参数：name={}", userQueryCondition.getName());
        log.info("分页信息：{},{},{}",pageable.getPageSize(),pageable.getPageNumber(),pageable.getSort());

        List<UserVo> list = Arrays.asList(new UserVo().setName(userQueryCondition.getName() + "1")
                , new UserVo().setName(userQueryCondition.getName() + "2")
                , new UserVo().setName(userQueryCondition.getName() + "3"));
        return ResponseEntity.ok(list);
    }

    @GetMapping("/{userId:\\d+}")
    public ResponseEntity getUserInfo(@PathVariable Long userId){
        UserVo userVo = userService.getUserInfo(userId);
        return ResponseEntity.ok(userVo);
    }




}
